package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.entity.GsCategory;
import edu.scau.mis.cloth.dao.GsCategoryDao;
import edu.scau.mis.cloth.service.GsCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (GsCategory)表服务实现类
 *
 * @author makejava
 * @since 2022-03-09 20:29:12
 */
@Service("gsCategoryService")
public class GsCategoryServiceImpl implements GsCategoryService {
    @Resource
    private GsCategoryDao gsCategoryDao;

    public List<GsCategory> queryAll(GsCategory category) {
        return this.gsCategoryDao.queryAll(category);
    }
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GsCategory queryById(Integer id) {
        return this.gsCategoryDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param gsCategory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsCategory> queryByPage(GsCategory gsCategory, PageRequest pageRequest) {
        long total = this.gsCategoryDao.count(gsCategory);
        return new PageImpl<>(this.gsCategoryDao.queryAllByLimit(gsCategory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param gsCategory 实例对象
     * @return 实例对象
     */
    @Override
    public GsCategory insert(GsCategory gsCategory) {
        this.gsCategoryDao.insert(gsCategory);
        return gsCategory;
    }

    /**
     * 修改数据
     *
     * @param gsCategory 实例对象
     * @return 实例对象
     */
    @Override
    public GsCategory update(GsCategory gsCategory) {
        this.gsCategoryDao.update(gsCategory);
        return this.queryById(gsCategory.getClCategoryId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.gsCategoryDao.deleteById(id) > 0;
    }
}
